﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using C.Unite;
using C.Entities;
using ChanExt;
using MySoft.Data;
using System.Text;
using LitJson;

namespace ArtLand.OA.Project.Project
{
    public partial class Pro_MeetingChange : CommonPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                txt_ATTEND.OnClientTriggerClick = Window1.GetSaveStateReference(hid_ATTEND.ClientID, txt_ATTEND.ClientID)
                   + Window1.GetShowReference("/PublicModel/SelectUsers.aspx", "选择人员");

                txt_CHRMAN.OnClientTriggerClick = Window1.GetSaveStateReference(hid_CHRMAN.ClientID, txt_CHRMAN.ClientID)
                   + Window1.GetShowReference("/PublicModel/SelectUsers.aspx", "选择人员");

                Load_Data();
            }
        }

        protected void Load_Data()
        {
            btnClose.OnClientClick = ActiveWindow.GetHideReference();
            if (!string.IsNullOrEmpty(Request["id"]))
            {
                int id = int.Parse(Request["id"]);
                Proj_Meeting MT = TbsDbSession.Default.From<Proj_Meeting>().Where(Proj_Meeting._.ID == id).ToFirst();
                if (MT != null)
                {
                    txt_CHRMAN.Text = MT.CHRMAN;
                    txt_ATTEND.Text = MT.ATTEND;
                    txt_STDATE.Text = MT.STDATE.Value.ToString("yyyy-MM-dd");
                    txt_STTIME.Text = MT.STTIME.Value.ToString("yyyy-MM-dd");
                    txt_EDTIME.Text = MT.EDTIME.Value.ToString("yyyy-MM-dd");
                    Drp_STATUS.SelectedValue = MT.STATUS.Value.ToString();
                    txt_MTOPIC.Text = MT.MTOPIC;
                    txt_SUBJET.Text = MT.SUBJET;
                    txt_SUMMAY.Text = MT.SUMMAY;
                    txt_SUMMID.Text = MT.SUMMID;
                    txt_REMARK.Text = MT.REMARK;
                    hid_ATTEND.Text = MT.ATTENDIDS;
                    hid_CHRMAN.Text = MT.CHRMANIDs;
                    txt_EDTIME_T.SelectedDate = MT.EDTIME.Value;
                    txt_STTIME_T.SelectedDate = MT.STTIME.Value;

                    txt_CHRMAN.Enabled = false;

                    txt_ATTEND.Enabled = false;
                    txt_STDATE.Enabled = false;
                    txt_STTIME.Enabled = false;
                    txt_EDTIME.Enabled = false;
                    // Drp_STATUS.Readonly = true;
                    txt_MTOPIC.Enabled = false;
                    txt_SUBJET.Enabled = false;
                    hid_ATTEND.Enabled = false;
                    hid_CHRMAN.Enabled = false;
                    txt_EDTIME_T.Enabled = false;
                    txt_STTIME_T.Enabled = false;


                }
            }
        }


        protected void btnSave_Click(object sender, EventArgs e)
        {
            bool yz = true;
            if (txt_CHRMAN.Text == "")
            {
                yz = false;
                txt_CHRMAN.MarkInvalid(String.Format("请输入会议主持人！", txt_CHRMAN.Text));
            }
            if (txt_ATTEND.Text == "")
            {
                yz = false;
                txt_ATTEND.MarkInvalid(String.Format("请输入会议参与人！", txt_ATTEND.Text));
            }
            if (txt_STDATE.Text == "")
            {
                yz = false;
                txt_STDATE.MarkInvalid(String.Format("请输入会议召开日期！", txt_STDATE.Text));
            }
            if (txt_MTOPIC.Text == "")
            {
                yz = false;
                txt_MTOPIC.MarkInvalid(String.Format("请输入会议主题！", txt_MTOPIC.Text));
            }
            if (txt_EDTIME.Text == "")
            {
                yz = false;
                txt_EDTIME.MarkInvalid(String.Format("请输入预估结束时间！", txt_EDTIME.Text));
            }
            if (txt_SUBJET.Text == "")
            {
                yz = false;
                txt_SUBJET.MarkInvalid(String.Format("请输入会议议程信息！", txt_SUBJET.Text));
            }
            if (txt_STTIME.Text == "")
            {
                yz = false;
                txt_STTIME.MarkInvalid(String.Format("请输入会议开始时间！", txt_STTIME.Text));
            }
            
            if (yz)
            {
                int returnvalue = 0;
                Proj_Meeting MT = new Proj_Meeting();
                if (!string.IsNullOrEmpty(Request["id"]))
                {
                    MT.ID = int.Parse(Request["id"]);
                    MT.Attach();
                    MT.SUMMAY = txt_SUMMAY.Text;
                    MT.SUMMID = txt_SUMMID.Text;
                    MT.REMARK = txt_REMARK.Text;
                    MT.STATUS = int.Parse(Drp_STATUS.SelectedValue);
                    returnvalue = TbsDbSession.Default.Update<Proj_Meeting>(MT);
                }
                else
                {
                    MT.DeAttach();
                    MT.METNUB = DFieldSN.SN(EnumData.DataSNEunm.会议编号);
                    MT.USERID = CookInfo.EAdminid();
                    MT.CHRMAN = txt_CHRMAN.Text;
                    MT.ATTEND = txt_ATTEND.Text;
                    MT.STDATE = Convert.ToDateTime(txt_STDATE.Text);
                    MT.STTIME = Convert.ToDateTime(txt_STTIME.Text + " " + txt_STTIME_T.Text);
                    MT.EDTIME = Convert.ToDateTime(txt_EDTIME.Text + " " + txt_EDTIME_T.Text);
                    MT.MTOPIC = txt_MTOPIC.Text;
                    MT.SUBJET = txt_SUBJET.Text;
                    MT.STATUS = int.Parse(Drp_STATUS.SelectedValue);
                    MT.SUMMAY = txt_SUMMAY.Text;
                    MT.SUMMID = txt_SUMMID.Text;
                    MT.REMARK = txt_REMARK.Text;
                    MT.AddTime = DateTime.Now;
                    MT.Adder = CookInfo.EAdminTrueName();
                    MT.CHRMANIDs = hid_CHRMAN.Text;
                    MT.ATTENDIDS = hid_ATTEND.Text;
                    returnvalue = TbsDbSession.Default.Insert<Proj_Meeting>(MT);
                }
                if (returnvalue > 0)
                {
                    Alert.Show("更新成功！", "提示", ActiveWindow.GetHideRefreshReference());
                }
            }
            else
            {
            }
        }
    }
}